﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Kokomo.Mirror.CliMetadata
{
	class CodedIndexPropertyDescriptor : MetadataRowPropertyDescriptor
	{
		public CodedIndexPropertyDescriptor(
			PropertyDescriptor baseDescriptor,
			MetadataContainer container
			)
			: base(baseDescriptor, container)
		{
		}

		public override object GetValue(object component)
		{
			ICustomTypeDescriptor descriptor = component as ICustomTypeDescriptor;
			CodedIndex index = (CodedIndex)this.BaseDescriptor.GetValue(descriptor.GetPropertyOwner(this));
			IMetadataRow row = this.Container.GetRow(index);

			return (row != null) ? new MetadataRowDescriptor(row, this.Container) : null;
		}

		public override Type PropertyType
		{
			get { return typeof(MetadataRowDescriptor); }
		}
	}
}
